package org.farm2.ai.test.client;

import com.alibaba.cloud.ai.dashscope.api.DashScopeImageApi;
import com.alibaba.cloud.ai.dashscope.image.DashScopeImageModel;
import com.alibaba.cloud.ai.dashscope.image.DashScopeImageOptions;
import org.farm2.ai.test.config.ApiConfig;
import org.springframework.ai.image.*;
import org.springframework.retry.support.RetryTemplate;

public class ImgDemo {
    public static void main(String[] args) {
        creatImg();
    }


    public static void creatImg() {
        String apiKey = ApiConfig.apiKey;
        // 创建 DashScope API 客户端
        DashScopeImageApi dashScopeApi = new DashScopeImageApi(apiKey);
        // 构建 ChatOptions（可选参数）
        ImageOptions options = ImageOptionsBuilder.builder()
                .model("wanx2.0-t2i-turbo")
                .build();

        DashScopeImageOptions options1 = new DashScopeImageOptions();
        options1.setModel("wanx2.0-t2i-turbo");
        // 手动创建 ChatModel 实例
        ImageModel imageModel = new DashScopeImageModel(dashScopeApi, options1, new RetryTemplate());
        ImagePrompt imagePrompt = new ImagePrompt("画一只拉粑粑的小鸡");
        ImageResponse response = imageModel.call(imagePrompt);
        String imageUrl = response.getResult().getOutput().getUrl();
        System.out.println(imageUrl);
    }


}
